{layout name="layout/food" /}
<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <div class="widget-body  am-margin-bottom-lg">
                    <div class="widget__order-detail am-u-sm-12">
                        <?php
                        // 计算当前步骤位置
                        $progress = 1;
                        $detail['pay_status']['value'] > 10 && $progress += 1;
                        $detail['delivery_status']['value'] == 30 && $progress += 1;
                        $detail['receipt_status']['value'] == 20 && $progress += 1;
                        $detail['order_status']['value'] == 30 && $progress += 1;
                        ?>
                        <ul class="order-detail-progress progress-{$progress}">
                            <li>
                                <span>下单时间</span>
                                <div class="tip">{$detail['create_time']}</div>
                            </li>
                            <li>
                                <span>付款时间</span>
                                {if $detail['pay_status']['value'] > 10}
                                    <div class="tip">
                                        {$detail['pay_time']|date='Y-m-d H:i'}
                                    </div>
                                {/if}
                            </li>
                            <li>
                                <span>配送时间</span>
                                {if $detail['delivery_status']['value'] == 30}
                                    <div class="tip">
                                        {$detail['delivery_time']|date='Y-m-d H:i'}
                                    </div>
                                {/if}
                            </li>
                            <li>
                                <span>收货时间</span>
                                {if $detail['receipt_status']['value'] == 20}
                                    <div class="tip">
                                        {$detail['receipt_time']|date='Y-m-d H:i'}
                                    </div>
                                {/if}
                            </li>
                            <li>
                                <span>{$detail['order_status']['value'] == 40 ? '退款时间' : '完成时间'}</span>
                               {if $detail['order_status']['value'] == 30}
                                    <div class="tip">
                                        {$detail['receipt_time']|date='Y-m-d H:i'}
                                    </div>
                                {elseif $detail['refund_status']['value'] == 20 /}
									<div class="tip">
                                        {$detail['refund_time']|date='Y-m-d H:i'}
                                    </div>
								{/if}
                            </li>
                        </ul>
                    </div>

                    <div class="widget-head am-cf">
                        <div class="widget-title am-fl">基本信息</div>
                    </div>
                    <div class="am-scrollable-horizontal">
                        <table class="am-table-hover regional-table am-table am-table-bordered am-table-centered
                            am-text-nowrap am-margin-bottom-xs">
                            <tbody>
                            <tr>
                                <th>订单号</th>
                                <th>付款信息</th>
                                <th>买家信息</th>
                                <th>买家留言</th>
                                <th>口味要求</th>
                                <th>交易状态</th>
                            </tr>
                            <tr>
                                <td>{$detail['order_no']}</td>
                                <td>
                                    <p>￥{$detail['pay_price']}</p>
                                    <p class="am-link-muted">(优惠额：-￥{$detail['activity_price']})</p>
                                    {if $detail['pack_price']>0}
                                        <p class="am-link-muted">(包装费：+￥{$detail['pack_price']})</p>
                                    {/if}
                                    {if $detail['express_price']>0}
                                        <p class="am-link-muted">(配送费：+￥{$detail['express_price']})</p>
                                    {/if}
                                    {if $detail['ware_price']>0}
                                        <p class="am-link-muted">(餐具费：+￥{$detail['ware_price']})</p>
                                    {/if}
                                    {if $detail['order_status']['value']==40}
                                        <p>退款：-￥{$detail['refund_price']}</p>
                                    {/if}
                                </td>
                                <td>
                                    <p>{$detail['user']['nickname']}</p>
                                    <p class="am-link-muted">(用户id：{$detail['user']['user_id']})</p>
                                </td>
                                <td>
                                    <p>{$detail['message']|default='--'}</p> 
                                </td>
                                <td>
                                    <p>{$detail['flavor']|default='--'}</p> 
                                </td>
                                <td>
                                     <p>付款状态：
                                        <span class="am-badge
                                    {$detail['pay_status']['value'] == 20 ? 'am-badge-success' : ''}
                                    {$detail['pay_status']['value'] == 30 ? 'am-badge-danger' : ''}">
                                            {$detail['pay_status']['text']}</span>
                                    </p>
                                    <p>接单状态：
                                        <span class="am-badge
                                    {$detail['shop_status']['value'] > 10 ? 'am-badge-success' : ''}">
                                            {$detail['shop_status']['text']}</span>
                                    </p>
                                    <p>配送状态：
                                        <span class="am-badge
                                    {$detail['delivery_status']['value'] == 20 ? 'am-badge-danger' : ''}
                                    {$detail['delivery_status']['value'] == 30 ? 'am-badge-success' : ''}">
                                            {$detail['delivery_status']['text']}</span>
                                    </p>
                                    <p>收货状态：
                                        <span class="am-badge
                                    {$detail['receipt_status']['value'] == 20 ? 'am-badge-success' : ''}">
                                            {$detail['receipt_status']['text']}</span>
                                    </p>
                                    <p>订单状态：
                                        <span class="am-badge
                                    {$detail['order_status']['value'] == 10 ? 'am-badge-warning' : ''}
                                    {$detail['order_status']['value'] == 20 ? 'am-badge-danger' : ''}
                                    {$detail['order_status']['value'] == 30 ? 'am-badge-success' : ''}
                                    {$detail['order_status']['value'] == 40 ? 'am-badge-danger' : ''}">
                                    {$detail['order_status']['value'] == 40 ? $detail['refund_status']['text'] : $detail['order_status']['text']}
                                        </span>
                                    </p>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>

                    <div class="widget-head am-cf">
                        <div class="widget-title am-fl">商品信息</div>
                    </div>
                    <div class="am-scrollable-horizontal">
                        <table class="am-table-hover regional-table am-table am-table-bordered am-table-centered
                            am-text-nowrap am-margin-bottom-xs">
                            <tbody>
                            <tr>
                                <th>商品名称</th>
                                <th>销售价格</th>
                                <th>购买数量</th>
								<th>售后数量</th>
                                <th>商品总价</th>
                            </tr>
                            {foreach $detail['goods'] as $goods}
                                <tr>
                                    <td class="goods-detail am-text-middle">
                                        <div class="goods-image">
                                            <img src="{$goods['image']['url']}" alt="">
                                        </div>
                                        <div class="goods-info">
                                            <p class="goods-title">{$goods['goods_name']}</p>
                                            <p class="goods-spec am-link-muted">
                                                {$goods['goods_attr']}
                                            </p>
                                        </div>
                                    </td>
                                    <td>￥{$goods['goods_price']}</td>
                                    <td>×{$goods['total_num']}</td>
									<td>{$goods['refund_num']?' - ' . $goods['refund_num'] : '--'}</td>
                                    <td>￥{$goods['total_price']}</td>
                                </tr>
                            {/foreach}
                            <tr>
                                <td colspan="5" class="am-text-right">总计金额：￥{$detail['total_price']}</td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <div class="widget-head am-cf">
                        <div class="widget-title am-fl">付款信息</div>
                    </div>
                    <div class="am-scrollable-horizontal">
                        <table class="am-table-hover regional-table am-table am-table-bordered am-table-centered
                            am-text-nowrap am-margin-bottom-xs">
                            <tbody>
                            <tr>
                                <th>应付款金额</th>
                                <th>支付方式</th>
                                <th>支付流水号</th>
                                <th>付款状态</th>
                                <th>付款时间</th>
                            </tr>
                            <tr>
                                <td>￥{$detail['pay_price']}</td>
                                <td>
                                {if $detail['pay_status']['value'] == 20}
                                    {if empty($detail['transaction_id'])}
                                        余额支付
                                    {else /}
                                        微信支付
                                    {/if}
                                {else /}
                                    --
                                {/if}
                                </td>
                                <td>{$detail['transaction_id']|default='--'}</td>
                                <td>
                                    <span class="am-badge
                                    {$detail['pay_status']['value'] == 20 ? 'am-badge-success' : ''}
                                    {$detail['pay_status']['value'] == 30 ? 'am-badge-danger' : ''}">
                                    {if $detail['pay_status']['value'] < 30}
                                        {$detail['pay_status']['text']}
                                    {else /}
                                        {$detail['order_mode']['value'] == 10?'餐后支付':''}
                                        {$detail['order_mode']['value'] == 20?'骑手代收':''}
                                        {$detail['order_mode']['value'] == 30?'到店支付':''}
                                    {/if}
                                    </span>
                                </td>
                                <td>
                                    {$detail['pay_time'] ? datetime($detail['pay_time']) : '--'}
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    <!--收货信息-->
					{if $detail['order_mode']['value']==20}
                    <div class="widget-head am-cf">
                        <div class="widget-title am-fl">收货信息</div>
                    </div>
                    <div class="am-scrollable-horizontal">
                        <table class="am-table-hover regional-table am-table am-table-bordered am-table-centered
                            am-text-nowrap am-margin-bottom-xs">
                            <tbody>
                            <tr>
                                <th>收货人</th>
                                <th>收货电话</th>
                                <th>收货地址</th>
                            </tr>
                            <tr>
                                <td>{$detail['address']['name']}</td>
                                <td>{$detail['address']['phone']}</td>
                                <td>
                                    {$detail['address']['province']}
                                    {$detail['address']['city']}
                                    {$detail['address']['district']}
                                    {$detail['address']['detail']}
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
					{/if}
                    
                    <!-- 外卖已配送 -->
                    {if $detail['order_mode']['value'] == 20 AND $detail['shop_status']['value']==30}
                    <div class="widget-head am-cf">
                        <div class="widget-title am-fl">骑手信息</div>
                    </div>
                    <div class="am-scrollable-horizontal">
                        <table class="am-table-hover regional-table am-table am-table-bordered am-table-centered
                        am-text-nowrap am-margin-bottom-xs">
                            <tbody>
                            <tr>
                                <th>骑手姓名</th>
                                <th>联系电话</th>
                                <th>骑手状态</th>
                                <th>配送状态</th>
                                <th>状态时间</th>
                            </tr>
                            <tr>
                                <td>{$detail['delivery']['linkman']}</td>
                                <td>{$detail['delivery']['phone']}</td>
                                <td>
                                     <span class="am-badge
                                    {$detail['delivery']['delivery_status']['value'] == 20 ? 'am-badge-warning' : ''}
                                    {$detail['delivery']['delivery_status']['value'] == 30 ? 'am-badge-warning' : ''}
                                    {$detail['delivery']['delivery_status']['value'] == 40 ? 'am-badge-warning' : ''}
                                    {$detail['delivery']['delivery_status']['value'] == 50 ? 'am-badge-success' : ''}">
                                        {$detail['delivery']['delivery_status']['text']}</span>
                                </td>
                                <td>
                                    <span class="am-badge
                                    {$detail['delivery']['status']['value'] == 10 ? 'am-badge-warning' : ''}
                                    {$detail['delivery']['status']['value'] == 20 ? 'am-badge-danger' : ''}
                                    {$detail['delivery']['status']['value'] == 30 ? 'am-badge-success' : ''}">
                                        {$detail['delivery']['status']['text']}</span>
                                </td>
                                <td>
                                    {$detail['delivery']['delivery_time'] ? datetime($detail['delivery']['delivery_time']) : '--'}
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </div>
                    {/if}
                    <!-- 退款信息 -->
					{if $detail['order_status']['value'] == 40}
					<form id="refund" class="my-form refund am-form tpl-form-line-form" method="post" action="">
						<div class="widget-head am-cf">
                            <div class="widget-title am-fl">退款信息</div>
                        </div>
                        <div class="am-scrollable-horizontal">
                            <table class="am-table-hover regional-table am-table am-table-bordered am-table-centered
                                am-text-nowrap am-margin-bottom-xs">
                                <tbody>
                                <tr>
                                    <th>退款金额</th>
                                    <th>返回账户</th>
                                    <th>退款理由</th>
                                    <th>退款状态</th>
                                    <th>退款时间</th>
                                </tr>
                                <tr>
                                    <td>￥{$detail['refund_price']}</td>
                                    <td>{$detail['transaction_id'] ?'微信':'余额'}</td>
                                    <td>{$detail['refund_desc']}</td>
                                    <td>
                                        <span class="am-badge
                                        {$detail['refund_status']['value'] == 20 ? 'am-badge-success' : 'am-badge-warning'}">
                                            {$detail['refund_status']['text']}</span>
                                    </td>
                                    <td>
                                        {$detail['refund_time'] ? datetime($detail['refund_time']) : '--'}
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
						{if $detail['refund_status']['value'] ==10}
						<p>
							<div class="am-form-group">
								<label class="am-u-sm-9 am-u-lg-3 am-form-label form-require">等待商家退款操作 </label>
								<div class="am-u-sm-3 am-u-end">
									<label class="am-radio-inline">
										<input type="radio" name="data[is_refund]" value="1" data-am-ucheck checked >
										同意
									</label>
									<label class="am-radio-inline">
										<input type="radio" name="data[is_refund]" value="0" data-am-ucheck>
										拒绝
									</label>
								</div>
							</div>
							<div class="am-form-group">
								<div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
									<button type="submit" class="j-submit am-btn am-btn-sm am-btn-secondary">
										确认操作
									</button>
								</div>
							</div>
						</p>
						{/if}
						</form>
					{/if}

                    <!-- 确认收款 -->
                    {if $detail['pay_status']['value'] == 30 AND $detail['delivery_status']['value'] == 30 AND $detail['order_status']['value'] == 10}
                    <form id="collection" class="my-form collection am-form tpl-form-line-form" method="post" action="">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">上餐完毕 - 等待商家收款</div>
                        </div>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                <button type="submit" class="j-submit am-btn am-btn-sm am-btn-secondary">确认收款</button>
                            </div>
                        </div>
                    </form>
                    {/if}

                    <!-- 商家接单 -->
                    {if $detail['pay_status']['value'] > 10 AND $detail['shop_status']['value'] == 10 AND $detail['order_status']['value'] == 10}
                    <form id="shop" class="my-form shop am-form tpl-form-line-form" method="post" action="">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">{$detail['pay_status']['value']==20 ?'已支付':'餐后支付'} - 待商家确认接单</div>
                        </div>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                <button type="submit" class="j-submit am-btn am-btn-sm am-btn-secondary">确认接单</button>
                            </div>
                        </div>
                    </form>
                    {/if}

                    <!-- 订单配送 -->
                    {if $detail['shop_status']['value'] == 20 AND $detail['delivery_status']['value'] == 10 AND $detail['order_status']['value'] == 10}
                    <form id="delivery" class="my-form delivery am-form tpl-form-line-form" method="post" action="">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">{$detail['order_mode']['value'] == 20 ? '等待外卖订单推送给骑手':'待商家发货'}</div>
                        </div>
                        {if $detail['order_mode']['value']==20}
                        <div class="am-form-group">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">选择配送方式 </label>
                            <div class="am-u-sm-9 am-u-end">
                                <label class="am-radio-inline">
                                    <input v-model="company" type="radio" name="data[company]" value="self" data-am-ucheck checked>
                                    商家自配
                                </label>
                                {foreach $company as $item}
                                <label class="am-radio-inline">
                                    <input v-model="company" type="radio" name="data[company]" value="{$item['name']}" data-am-ucheck>
                                     {$item['title']}
                                </label>
                                {/foreach}
                            </div>
                        </div>
                        <!--
                        {if $detail['shop']['is_grab']['value']==0}
                        -->
                        <div class="am-form-group" v-if="company == 'self'">
                            <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">指派骑手 </label>
                            <div class="am-u-sm-9 am-u-end">
                                <select name="data[shop_clerk_id]" required  style="width:200px;">
                                    <option value="">请选择配送员</option>
                                    {if isset($clerk)}
                                        {foreach $clerk as $item}
                                        <option value="{$item['shop_clerk_id']}">{$item['real_name']}</option>
                                        {/foreach}
                                    {/if}
                                </select>
                            </div>
                        </div>
                        <!-- 
                        {else /}
                        <input type="hidden" name="data[shop_clerk_id]" value="">
                        {/if}
                        -->
                        {else /}
                        <input type="hidden" name="data[company]" value="">
                        <input type="hidden" name="data[shop_clerk_id]" value="">
                        {/if}
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                <button type="submit" class="j-submit am-btn am-btn-sm am-btn-secondary">{$detail['order_mode']['value'] == 20 ? '确认推送':'确认发货'}</button>
                            </div>
                        </div>
                    </form>
                    {/if}

                    <!-- 骑手已到店 -->
                    {if $detail['order_mode']['value'] == 20 AND $detail['delivery_status']['value'] == 20 AND $detail['delivery']['delivery_status']['value'] == 20 AND $detail['order_status']['value'] == 10}
                    <form id="dev30" class="my-form delivery-status am-form tpl-form-line-form" method="post" action="">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">待骑手到店取货</div>
                            <input type="hidden" name="data[delivery_status]" value="30">
                        </div>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                <button type="submit" class="j-submit am-btn am-btn-sm am-btn-secondary">骑手取货</button>
                            </div>
                        </div>
                    </form>
                    {/if}
                    <!-- 外卖开始配送 -->
                    {if $detail['order_mode']['value'] == 20 AND $detail['delivery_status']['value'] == 20 AND $detail['delivery']['delivery_status']['value'] == 30 AND $detail['order_status']['value'] == 10}
                    <form id="dev40" class="my-form delivery-status am-form tpl-form-line-form" method="post" action="">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">骑手已取货，等待配送</div>
                            <input type="hidden" name="data[delivery_status]" value="40">
                        </div>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                <button type="submit" class="j-submit am-btn am-btn-sm am-btn-secondary">开始配送</button>
                            </div>
                        </div>
                    </form>
                    {/if}
                    <!-- 外卖送达 -->
                    {if $detail['order_mode']['value'] == 20 AND $detail['delivery_status']['value'] == 20 AND $detail['delivery']['delivery_status']['value'] == 40 AND $detail['order_status']['value'] == 10}
                    <form id="dev50" class="my-form delivery am-form tpl-form-line-form" method="post" action="">
                        <div class="widget-head am-cf">
                            <div class="widget-title am-fl">外卖已送达待确认</div>
                            <input type="hidden" name="data[company]">
                        </div>
                        <div class="am-form-group">
                            <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                <button type="submit" class="j-submit am-btn am-btn-sm am-btn-secondary">确认送达</button>
                            </div>
                        </div>
                    </form>
                    {/if}
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/assets/plugins/vue/vue.min.js"></script>
<script>
    $(function () {
        new Vue({
          el: '.my-form',
          data: {
            company:'self'
          }
        });
        $('.refund').formPost({"url":"/store/food.order/refund?id={$detail['order_id']}"});
        $('.collection').formPost({"url":"/store/food.order/collection?id={$detail['order_id']}"});
        $('.shop').formPost({"url":"/store/food.order/shop?id={$detail['order_id']}"});
        $('.delivery').formPost({"url":"/store/food.order/delivery?id={$detail['order_id']}"});
        $('.delivery-status').formPost({"url":"/store/food.order/deliveryStatus?id={$detail['order_id']}"});
    });
</script>
